package adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import bean.LunTanSchoolNewsBean;
import jiyun.com.yiyanmeng.R;
import jiyun.com.yiyanmeng.SheQuSchoolDetailActivity;
import utils.ToastUtil;

/**
 * Created by zhang'lin'lin on 2019/11/7.
 */

public class LunTanNewsAdapter extends RecyclerView.Adapter {
    private List<LunTanSchoolNewsBean> news_list;
    private Context context;

    public LunTanNewsAdapter(List <LunTanSchoolNewsBean> news_list, Context context) {
        this.news_list = news_list;
        this.context = context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_luntannews_xuexiao, parent, false);
        return new NewsVH(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
        NewsVH newsVH= (NewsVH) holder;
        newsVH.tv1.setText(news_list.get(position).getTitle());
        newsVH.tv2.setText(news_list.get(position).getSchool_name());
        newsVH.tv3.setText(news_list.get(position).getPing_num());
        newsVH.tv4.setText(news_list.get(position).getGuan_num());
        Glide.with(context).load(news_list.get(position).getThumb()).into(newsVH.iv);
        //整个条目点击
        newsVH.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                   monItemClick.onClick(position);
                Intent intent = new Intent(context, SheQuSchoolDetailActivity.class);
                String cate_id = news_list.get(position).getId();
                int id = Integer.parseInt(cate_id);
                intent.putExtra("id",id);
                context.startActivity(intent);
            }
        });


    }

    @Override
    public int getItemCount() {
        return news_list.size();
    }

    //条目接口回调
    class NewsVH extends RecyclerView.ViewHolder{

        private final ImageView iv;
        private final TextView tv1;
        private final TextView tv2;
        private final TextView tv3;
        private final TextView tv4;

        public NewsVH(View itemView) {
            super(itemView);
            iv = itemView.findViewById(R.id.image);
            tv1 = itemView.findViewById(R.id.tv_content);
            tv2 = itemView.findViewById(R.id.tv_school_name);
            tv3 = itemView.findViewById(R.id.txt_ping_num);
            tv4 = itemView.findViewById(R.id.tv_guan_num);
        }
    }

    public interface onItemClick{
        void onClick(int position);
    }
    private onItemClick monItemClick;

    public void setMonItemClick(onItemClick monItemClick) {
        this.monItemClick = monItemClick;
    }


}
